<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="姓名" prop="roleName">
        <el-select
          v-model="queryParams.roleName"
          multiple
          filterable
          remote
          reserve-keyword
          placeholder="请输入关键词"
          :remote-method="remoteMethod">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item> 
      <el-form-item label="拉黑时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          @click="$emit('change', 'List')"
        >返回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-tickets"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:role:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-warning"
          size="mini"
          @click="removeBlack"
          v-hasPermi="['system:role:remove']"
        >移除黑名单</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" :index="indexMethod" width="80" />
      <el-table-column label="姓名" prop="roleName" />
      <el-table-column label="性别" prop="roleKey"  />
      <el-table-column label="手机号" prop="roleSort" />
      <el-table-column label="拉黑时间" prop="roleSort" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新增对话框 -->
    <el-dialog title="新增" :visible.sync="open" width="800px" append-to-body>
      <el-form :model="form1" label-width="80px" :inline="true">
        <el-form-item label="姓名">
          <el-select
            v-model="form1.name"
            multiple
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery1">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery1">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="list1" @selection-change="handleSelectionChange1">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="姓名" prop="roleName" />
        <el-table-column label="性别" prop="roleKey"  />
        <el-table-column label="手机号" prop="roleSort" />
      </el-table>
      <pagination
        v-show="total1>0"
        :total="total1"
        :page.sync="queryParams1.pageNum"
        :limit.sync="queryParams1.pageSize"
        @pagination="getList1"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确 定</el-button>
        <el-button @click="open=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRole } from "@/api/system/role";

export default {
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 多选数组集合
      ids: [],
      // 弹窗多选数组集合
      ids1: [],
      // 下拉数据
      options: [],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      total1: 0,
      // 表格数据
      list: [],
      list1: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined
      },
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined
      },
      form1: { name: '' },
      // 拉黑时间
      dateRange: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 移除黑名单
    removeBlack() {

    },
    // 选择列表
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roleId)
    },
    // 选择列表
    handleSelectionChange1(selection) {
      this.ids = selection.map(item => item.roleId)
    },
    // 模糊搜索
    remoteMethod(query) {
      
    },
    indexMethod(index) {
      return (this.queryParams.pageNum- 1) * this.queryParams.pageSize + index + 1;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    getList1() {
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.list1 = response.rows;
          this.total1 = response.total;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleQuery1() {
      this.queryParams1.pageNum = 1;
      this.getList1();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    resetQuery1() {
      this.form1.name = ''
      this.handleQuery1();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.getList1()
      this.form1.name = ''
      this.open = true;
    },
    // 弹窗确定
    submit() {
      
    }
  }
};
</script>
